package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.bo.CommonListBo;
import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.cskaoyan.market.service.AdminCollectService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminCollectServiceImpl implements AdminCollectService {

    @Autowired
    MarketCollectMapper marketCollectMapper;
    @Override
    public List<MarketCollect> list(CommonListBo commonListBo) {
        Integer page = commonListBo.getPage();
        Integer limit = commonListBo.getLimit();
        String sort = commonListBo.getSort();
        String order = commonListBo.getOrder();
        MarketCollectExample marketAddressExample = new MarketCollectExample();
        MarketCollectExample.Criteria criteria = marketAddressExample.createCriteria();
        if(!StringUtils.isEmpty(commonListBo.getUserId().toString()))
            criteria.andUserIdEqualTo(commonListBo.getUserId());
        if(!StringUtils.isEmpty(commonListBo.getValueId().toString())) {
            criteria.andUserIdEqualTo(commonListBo.getValueId());
        }
        marketAddressExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(page,limit);
        List<MarketCollect> marketCollects = marketCollectMapper.selectByExample(marketAddressExample);
        return marketCollects;
    }
}
